-
Notifications
You must be signed in to change notification settings - Fork 340
Refactor the task module #421
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
src/task/executor/pool.rs
Outdated
// chosen point. | ||
pool.stealers | ||
.iter() | ||
.chain(pool.stealers.iter()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Heh, so how does this work? The chaining of pool.stealers
with itself kind of confuses me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it's a bit weird. :) I changed the code to:
// Try stealing a batch of tasks from each local queue starting from the
// chosen point.
let (l, r) = pool.stealers.split_at(start);
let rotated = r.iter().chain(l.iter());
rotated.map(|s| s.steal_batch_and_pop(&local)).collect()
Hopefully now it's a bit clearer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see now. Yeah that's better. Thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
Okay, this is a big PR. Sorry 😅
Nothing is fundamentally different from the previous implementation - I mostly reorganized the modules so that it becomes clearer what is where and what is what. While this doesn't really change our task executor, some small tweaks and the nature of cleaning things up made it a bit more efficient.
My primary motive here was to clearly separate what is the public API (what is visible in the generated docs for
async_std::task
) and what is the task executor, i.e. the "machine" driving the module.The executor now lives in the
crate::task::driver
module, and everything else is an implementation of the high-level API that really has nothing to do with the executor. For example,task_local!
andblock_on()
have meaty implementations, but are not a part of the executor itself and therefore that code does not live in thedriver
module.There is also additional documentation and comments now, which should help contributors navigate the code more easily. In particular, I want people not interested in low-level details to not be lost in the codebase and people who are interested to be able to effortlessly play with the executor implementation without having to mess with anything that is unrelated to task execution.
This is the
task
module: https://github.com/stjepang/async-std/tree/refactor-task/src/taskThis is the
task::driver
module: https://github.com/stjepang/async-std/tree/refactor-task/src/task/driverThe scheduler is less than 150 lines of code and this is its main part: https://github.com/stjepang/async-std/blob/refactor-task/src/task/driver/pool.rs